var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../utils/config.js")), e = require("../../utils/api.js"), a = require("../../utils/util.js"), s = (require("../../wxParse/wxParse.js"), 
require("../../utils/wxApi.js"), require("../../utils/wxRequest.js"));

getApp();

Page({
    data: {
        title: "文章列表",
        postsList: {},
        pagesList: {},
        categoriesList: {},
        postsShowSwiperList: {},
        isLastPage: !1,
        page: 1,
        search: "",
        categories: 0,
        categoriesName: "",
        categoriesImage: "",
        showerror: "none",
        isCategoryPage: "none",
        isSearchPage: "none",
        showallDisplay: "block",
        displaySwiper: "block",
        floatDisplay: "none",
        searchKey: "",
        topBarItems: [ {
            id: "1",
            name: "评论数",
            selected: !0
        }, {
            id: "2",
            name: "浏览数",
            selected: !1
        }, {
            id: "3",
            name: "点赞数",
            selected: !1
        } ],
        tab: "1"
    },
    formSubmit: function(t) {
        var e = "../list/list";
        "" != t.detail.value.input && (e = e + "?search=" + t.detail.value.input), wx.navigateTo({
            url: e
        });
    },
    onShareAppMessage: function() {
        return {
            title: "分享“" + t.default.getWebsiteName + "”的文章排行。",
            path: "pages/hot/hot",
            success: function(t) {},
            fail: function(t) {}
        };
    },
    reload: function(t) {
        var e = this;
        e.fetchPostsData(e.data);
    },
    onTapTag: function(t) {
        for (var e = this, a = t.currentTarget.id, s = e.data.topBarItems, i = 0; i < s.length; i++) a == s[i].id ? s[i].selected = !0 : s[i].selected = !1;
        e.setData({
            topBarItems: s,
            tab: a
        }), 0 !== a ? this.fetchPostsData(a) : this.fetchPostsData("1");
    },
    onLoad: function(t) {
        this.fetchPostsData("1");
    },
    onShow: function(t) {},
    fetchPostsData: function(t) {
        var i = this;
        i.setData({
            postsList: []
        }), wx.showLoading({
            title: "正在加载",
            mask: !0
        }), s.getRequest(e.getTopHotPosts(t)).then(function(t) {
            200 === t.statusCode ? i.setData({
                showallDisplay: "block",
                floatDisplay: "block",
                postsList: i.data.postsList.concat(t.data.map(function(t) {
                    var e = t.post_date;
                    return null != t.post_thumbnail_image && "" != t.post_thumbnail_image || (t.post_thumbnail_image = "../../images/logo700.png"), 
                    t.post_date = a.cutstr(e, 10, 1), t;
                }))
            }) : 404 === t.statusCode && console.log("加载数据失败,可能缺少相应的数据");
        }).catch(function() {
            wx.hideLoading(), 1 == data.page && i.setData({
                showerror: "block",
                floatDisplay: "block"
            });
        }).finally(function() {
            setTimeout(function() {
                wx.hideLoading();
            }, 1500);
        });
    },
    redictDetail: function(t) {
        var e = "../detail/detail?id=" + t.currentTarget.id;
        wx.navigateTo({
            url: e
        });
    }
});